<?php
/*
 * dev florent di bartolo
 * htpp://florent.dibartolo.free.fr/
 */

function lol($var){
	echo "deleted=$var";
}

function deleteSelectedImage($var){
	
	//echo "deleted=$var";
	
	$table='images';
	
	$column='nom_image';
	
	$folder1='images';
	$folder2='imagespreview';
	
	dbconnect();
	
	$sql = "SELECT {$column} FROM {$table} WHERE id_image = {$var} LIMIT 1";
	$result = mysql_query($sql);
    $img = mysql_fetch_assoc($result);
	
	$name=$img['nom_image'];
	
	
	
	$query = "DELETE FROM {$table} WHERE id_image = {$var} LIMIT 1";
	$result = mysql_query($query);
	
	if(mysql_affected_rows()==1) {
		
		echo "deleted=$var";
		//echo "Deleted image: ".$name;
		
		unlink('../'.$folder1.'/'.$name);
		unlink('../'.$folder2.'/'.$name);

		
	} else {
		echo 'deleted=error';
		//echo 'Fail: '.mysql_error();
	}

	dbclose();

}


//---------------------- init duplicate -----------------------------------//

$path_http = "http://dev.citu.fr/infinity/";

$path_local = "/var/www/vhosts/citu.fr/sd/dev/www/infinity/";


// +++++ database connection data +++++

$hn =		"localhost"; 				// define hostname
$db =		"citu_infinity"; 				// define database name
$dbuser =	"citu_dev";		 			// database user
$dbpass =	"utic9742"; 				// password


// +++++ database connection functions +++++

function dbconnect() {
	global $hn, $db, $con, $dbpass, $dbuser;
	$con = @mysql_connect($hn, $dbuser, $dbpass);
	$db_sel = @mysql_select_db($db, $con);
	if (!$db_sel) {
		dbconnectdev();
	}
}

function dbconnectdev() {
	global $hn, $db, $con, $dbpass, $dbuser;
	$con = @mysql_connect($hn);
	$db_sel = @mysql_select_db($db, $con);
	if (!$db_sel) {
		//echo "could not connect to database $db ! please go back and try again.";
		exit;
	}
}

function dbclose() {
	global $con;
	mysql_close($con);
}


?>
